<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      header {
        width: 100%;
        height: 60px;
        text-align: center;
        line-height: 60px;
        border-bottom: 1px solid #000;
        font-size: 24px;
      }

      li {
        width: 345px;
        margin: 15px;
        border: 1px solid #000;
        list-style: none;
      }

      form {
        position: fixed;
        width: 100%;
        height: 70px;
        border-top: 1px solid #000;
        left: 0;
        bottom: 0;
        display: flex;
        justify-content: space-evenly;
        align-items: center;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <blog></blog>
    </div>

    <script src="../Vue.js"></script>
    <script>
      // 创建整个页面的大组件
      Vue.component("Blog", {
        data() {
          return {
            size: 16,
            news: [
              {
                title: "踏访万里长江第一城",
                content: "谈古，宜宾有2200多年建城史，是我国历史文化名城；",
              },
              {
                title: "沿着总书记的足迹之山东篇",
                content: "党的十八大以来，习近平总书记三次到山东考察调研",
              },
              {
                title: "美国排挤遏制他国必将失败",
                content:
                  "制衡中国在本地区利益的最好方法是积极构建美方的经济愿景",
              },
            ],
          };
        },
        template: `
          <div :style="{fontSize: size + 'px'}">
            <blog-header @big="big"></blog-header>
            <blog-list :news="news"></blog-list>
            <blog-form></blog-form>
          </div>
        `,
        methods: {
          big(s) {
            this.size += s;
          },
        },
      });

      // 头部组件
      Vue.component("BlogHeader", {
        data() {
          return {
            s: 2,
          };
        },
        template: `
          <header>
            微博头部
            <button @click="handleClick">+</button>
          </header>
        `,
        methods: {
          handleClick() {
            this.$emit("big", this.s);
          },
        },
      });

      // 列表组件
      Vue.component("BlogList", {
        props: ["news"],
        template: `
          <ul>
            <blog-list-item
              v-for="(item, index) in news"
              :key="index"
              :title="item.title"
              :content="item.content"
            >
            </blog-list-item>
          </ul>
        `,
      });

      // 列表的item组件
      Vue.component("BlogListItem", {
        props: ["title", "content"],
        template: `
          <li>
            <h3>{{ title }}</h3>
            <p>{{ content }}</p>
            <blog-button text="点赞"></blog-button>
          </li>
        `,
      });

      // 表单组件
      Vue.component("BlogForm", {
        template: `
          <form>
            <input type="text" />
            <blog-button text="发布"></blog-button>
          </form>
        `,
      });

      // 按钮组件
      Vue.component("BlogButton", {
        props: ["text"],
        template: `
          <button>{{text}}</button>
        `,
      });

      new Vue({
        el: "#app",
        data: {},
      });
    </script>
  </body>
</html>
